﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Frogism.Core;
using Frogism.Web.Controllers;

namespace Frogism.Web.Views.Money {
  public partial class NetWorthSummary : System.Web.Mvc.ViewUserControl<INetWorthViewData> {
    protected override void OnLoad(EventArgs e) {
      base.OnLoad(e);
      NetWorthList.ItemDataBound += new EventHandler<System.Web.UI.WebControls.ListViewItemEventArgs>(NetWorthList_ItemDataBound);
      if(!Page.IsPostBack) {
        NetWorthList.DataSource = ViewData.Model.NetWorthItems;
        NetWorthList.DataBind();
      }
    }

    void NetWorthList_ItemDataBound(object sender, System.Web.UI.WebControls.ListViewItemEventArgs e) {
      if (e.Item.ItemType == System.Web.UI.WebControls.ListViewItemType.DataItem) {
        var item = e.Item as System.Web.UI.WebControls.ListViewDataItem;
        var data = item.DataItem as NetWorthItem;

          if(data.Label == "Liquid"){
            var tc = (System.Web.UI.HtmlControls.HtmlTableCell)item.Controls[0].FindControl("ChangeCell");
            if (tc != null) {
              tc.Style.Add("background-color", "yellow");
            }
          }

      }
    }
  }
}
